package org.example.config;

import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.context.annotation.Bean;

import javax.sql.DataSource;

public class MyBatisConfig {

    //获取sqlSessionFactory对象
    @Bean
    public SqlSessionFactoryBean sqlSessionFactory(DataSource dataSource){
        SqlSessionFactoryBean ssfb = new SqlSessionFactoryBean();
        //设置数据源
        ssfb.setDataSource(dataSource);
        return ssfb;
    }

    //扫描映射文件
    @Bean
public MapperScannerConfigurer mapperScannerConfigurer(){
        MapperScannerConfigurer mps = new MapperScannerConfigurer();
        mps.setBasePackage("org.example.mapper");
        return mps;

}

}
